//
//  LGCultureButtonControl.m
//  ligenyun
//
//  Created by Mac on 2018/4/4.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCultureButtonControl.h"

@implementation LGCultureButtonControl

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, self.width-2, self.height)
                                                    text:title
                                               textColor:FirstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
        [self addSubview:self.titleLable];
        self.titleLable.centerY = self.height / 2;
        
        self.lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2, self.height / 3)];
        self.lineView.backgroundColor = OE_LIMITE_COLOR;
        self.lineView.hidden = YES;
        self.lineView.centerY = self.height/2;
        [self addSubview:self.lineView];
        [self addTarget:self action:@selector(onselctedControl:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    
    if (selected) {
        self.lineView.hidden = NO;
        self.titleLable.backgroundColor = UIColor.whiteColor;
        self.titleLable.layer.cornerRadius = NO;
        self.titleLable.clipsToBounds = YES;
        self.titleLable.textColor = UIColorFromRGBA(0x151515) ;
    }else{
        self.lineView.hidden = YES;
        self.titleLable.backgroundColor = UIColorFromRGBA(0xF1F1F1);
        self.titleLable.textColor = UIColorFromRGBA(0x4D4D4D);
        self.titleLable.clipsToBounds = NO;
    }
}
- (void)onselctedControl:(LGCultureButtonControl*)control{
    if (self.onSelectedControl) {
        self.onSelectedControl(control);
    }
}
@end
